var addBtn = document.getElementById('add');
var subBtn = document.getElementById('sub');
var getN = document.getElementById('getN');
var n = 1;
addBtn.addEventListener("click",addInfo);
subBtn.addEventListener("click",subInfo);

//添加让用户填的信息
function addInfo() {
    if(n >= 6){
        alert("当前已经达到最大入住人数");
    }else{
        n++;
        getN.value = n.toString();
        let div = document.getElementById('div'+n);
        div.style.display="block";
    }
}

function subInfo() {
    if(n <= 1){
        alert("当前已经达到所填人数最小");
    }else{
        let div = document.getElementById("div"+n);
        div.style.display = "none";
        n--;
        getN.value = n.toString();
    }
}

var select = document.getElementById("selectType");

function change() {
    var index = select.selectedIndex;
    var text = select.options[index].text;
    var url = "http://localhost:8080/HotelSystem/registerInHome.jsp?type=";
    url = url+text;
    url = encodeURI(encodeURI(url));
    window.location.href=url;
} 


var index = select.selectedIndex;
var text = select.options[index].text;
var money = 0;
if(text=="单人间"){
    money = 100;
}else if(text=="标准间"){
    money = 150;
}else if(text=="高级标间"){
    money = 200;
}else if(text=="三人间"){
    money = 250;
}else if(text=="豪华套间"){
    money = 400;
}

var earnest = document.getElementById("earnest");
var indate = document.getElementById("indate");
var outdate = document.getElementById("outdate");
var roomid = document.getElementById("roomid");
function setEarnest() {
    var indateValue = indate.value;
    var outdateValue = outdate.value;
    var roomidValue = roomid.value;
    if(indateValue!=null&&indateValue!=""&&outdateValue!=null&&outdateValue!=""&&roomidValue!=null&&roomidValue!=""){
        var n = ((Number)(new Date(outdateValue).getTime()-new Date(indateValue).getTime()))/(24*60*60*1000);
        if(n==0){
        	var earnestMoney = money+100;
            earnest.value = earnestMoney;
        }else{
        	 var earnestMoney = n*money+100;
             earnest.value = earnestMoney;
        }
    }
    setTimeout(setEarnest,2000);
}

setEarnest();

//var earnest = document.getElementById("earnest");
//var indate = document.getElementById("indate");
//var outdate = document.getElementById("outdate");
//function setEarnest() {
//	alert("111");
//    alert(indate.value);
//    setTimeout(setEarnest,2000);
//}
//
//setEarnest();